package com.ruoyi.project.module.record.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.constant.BusinessType;
import com.ruoyi.project.module.record.domain.Record;
import com.ruoyi.project.module.record.service.IRecordService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;

/**
 * 认证车源检测记录 信息操作处理
 * 
 * @author ruoyi
 * @date 2018-07-17
 */
@Controller
@RequestMapping("/module/record")
public class RecordController extends BaseController
{
    private String prefix = "module/record";
	
	@Autowired
	private IRecordService recordService;
	
	@RequiresPermissions("module:record:view")
	@GetMapping()
	public String record()
	{
	    return prefix + "/record";
	}
	
	/**
	 * 查询认证车源检测记录列表
	 */
	@RequiresPermissions("module:record:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Record record)
	{
		startPage();
        List<Record> list = recordService.selectRecordList(record);
		return getDataTable(list);
	}
	
	/**
	 * 新增认证车源检测记录
	 */
	@RequiresPermissions("module:record:add")
	@Log(title = "认证车源检测记录", action = BusinessType.INSERT)
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}

	/**
	 * 修改认证车源检测记录
	 */
	@RequiresPermissions("module:record:edit")
	@Log(title = "认证车源检测记录", action = BusinessType.UPDATE)
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, Model model)
	{
		Record record = recordService.selectRecordById(id);
		model.addAttribute("record", record);
	    return prefix + "/edit";
	}
	
	/**
	 * 保存认证车源检测记录
	 */
	@RequiresPermissions("module:record:save")
	@Log(title = "认证车源检测记录", action = BusinessType.SAVE)
	@PostMapping("/save")
	@ResponseBody
	public AjaxResult save(Record record)
	{
		if (recordService.saveRecord(record) > 0)
		{
			return success();
		}
		return error();
	}
	
	/**
	 * 删除认证车源检测记录
	 */
	@RequiresPermissions("module:record:remove")
	@Log(title = "认证车源检测记录", action = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{
		int rows = recordService.deleteRecordByIds(ids);
		if (rows > 0)
        {
            return success();
        }
        return error();
	}
	
}
